﻿using System;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Collections.Generic;

namespace System.Custom
{
   public static class Cultures
   {
      static List<string> FCountries;
      static List<CultureInfo> FNeutralCultures;
      static List<CultureInfo> FSpecificCultures;

      public static string[] Countries
      {
         get
         {
            if (FCountries == null)
            {
               FCountries = new List<string>();
               List<RegionInfo> regions = Specific.Select(ci => new RegionInfo(ci.LCID)).Distinct().ToList();
               regions.Sort((r1, r2) => r1.DisplayName.TrimIgnoreNull().CompareTo(r2.DisplayName.TrimIgnoreNull()));
               FCountries.AddRange(regions.Select(r => r.DisplayName.TrimIgnoreNull()));
            }
            return FCountries.ToArray();
         }
      }
      public static CultureInfo[] Neutral
      {
         get
         {
            if (FNeutralCultures == null)
            {
               FNeutralCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures).Where(c => c.LCID != CultureInfo.InvariantCulture.LCID).ToList();
               FNeutralCultures.Sort((c1, c2) => c1.DisplayName.CompareTo(c2.DisplayName));
            }
            return FNeutralCultures.ToArray();
         }
      }
      public static CultureInfo[] Specific
      {
         get
         {
            if (FSpecificCultures == null)
            {
               FSpecificCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures).ToList();
               FSpecificCultures.Sort((c1, c2) => c1.DisplayName.CompareTo(c2.DisplayName));
            }
            return FSpecificCultures.ToArray();
         }
      }
   }
}
